home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr40 / x1j4_src.zip / L2MISC.C < prev    next >
Text File  |  1995-01-21  |  8KB  |  267 lines

  1. /*****************************************************************************/
  2. /*                                              */
  3. /*                                         */
  4. /*    *****              *****                      */
  5. /*     *****            *****                         */
  6. /*       *****          *****                         */
  7. /*         *****        *****                         */
  8. /*  ***************      ***************                     */
  9. /*  *****************    *****************                     */
  10. /*  ***************      ***************                     */
  11. /*         *****        *****       TheNet                    */
  12. /*       *****          *****       Portable. Compatible.         */
  13. /*     *****            *****       Public Domain             */
  14. /*    *****              *****    G8KBB                  */
  15. /*                                         */
  16. /* This software is public domain ONLY for non commercial use                */
  17. /*                                                                           */
  18. /*                                         */
  19. /*                                                                           */
  20. /* September 1993 - released as TheNet X-1J                                  */
  21. /* added texnet support to checkheard()                                      */
  22. /*                                                                           */
  23. /* Add support for l3mheard optionally on L3MONITOR                         */
  24. /* Add link list reverse link checking in integrity()                        */
  25. /* Add pk96 watchdog calls                                                   */
  26. /*                                                                           */
  27. /* Released as TheNet X-1J release 4, January 1995                           */
  28. /*****************************************************************************/
  29.  
  30. #include "all.h"
  31. #include "tntyp.h"
  32.  
  33. #ifdef MONITORCMD
  34. extern lhtyp heardl;
  35. extern char txfhdr[];
  36. extern char rxfprt;
  37. extern unsigned seconds;
  38. extern unsigned char mhlcount;
  39. extern unsigned char DEFMHL;
  40. extern unsigned heardtm;
  41. extern unsigned runtime, uptime;
  42. extern MHEARD *mhptr;
  43. #endif
  44. #ifdef INTEGRITY
  45. extern lhtyp destil;
  46. extern lhtyp neigbl;
  47. extern lhtyp Arp_tab;
  48. extern lhtyp IP_Routes;
  49. #endif
  50.  
  51. extern unsigned char rxfdev;
  52. extern unsigned char siglev;
  53.  
  54. #ifdef ACL
  55. extern ACLMB acl;
  56. #endif
  57.  
  58. /* called from the level 2 software, this utility checks the heard list to see
  59.  * when and if the station was last heard. If not heard, it creates an entry,
  60.  * if it had been heard, the packet counter is bumped. In each case, the
  61.  * 'lastheard' timer is set to the currenttime, and the station is moved to
  62.  * the head of the list. Finally, if there are too many entries, the extra
  63.  * are removed.
  64.  */
  65.  
  66. #ifdef MONITORCMD
  67.  
  68. #ifdef L3MONITOR
  69. checkheard( lst, callsign, count)
  70. MHEARD *lst;
  71. char *callsign;
  72. unsigned char count;
  73. {
  74.     register MHEARD *mhp;
  75.     register int i;
  76.     register MHEARD *list = lst;
  77.  
  78.     i = 0;
  79.     mhp = list->prevhb;            /*start with one end of list*/
  80.     while( mhp != list )            /* step thru all entries    */
  81.         if( cmpid( mhp->call, callsign ) )
  82.             break;            /* stop if match found      */
  83.         else                /* otherwise,               */
  84.         {
  85.             i++;            /* bump the counter         */
  86.             mhp = mhp->prevhb;    /* and step on to the next  */
  87.         }
  88.     if( mhp != list )            /* if a match was found,    */
  89.     {
  90.         unlink( mhp );            /* then unlink it's buffer  */
  91.         mhp->packets++;            /* and increment pkt count  */
  92.     }
  93.     else                    /* otherwise ,              */
  94.     {
  95.         mhp = allocb();            /* allocate a new buffer    */
  96.         cpyid( mhp->call, callsign );    /* copy callsign into buffer*/
  97. #ifdef TEXNET
  98.         mhp->istexnet =
  99. #endif
  100.         mhp->isnode = mhp->istcpip = 0;    /* clear flags              */
  101.         mhp->packets = 1;        /* initialise packet count  */
  102.     }
  103.     mhp->port = rxfprt;            /* record which port heard  */
  104.     relink( mhp, list->prevhb );        /* put it at list head      */
  105.     mhp->lastheard = seconds;        /* mark heard time as 'now' */
  106. #ifdef METERS
  107.     mhp->dev = rxfdev;
  108.     mhp->sig_level = siglev;
  109. #endif
  110.     mhptr = mhp;                /* If too long, clear oldest*/
  111.     while( i-- >= count )            /* which is why we used 'i' */
  112.     {
  113.         mhp = list->nexthb;        /* clear out from end of lst*/
  114.         dealoc( unlink( mhp ));        /* and return to free pool  */
  115.     }
  116. }
  117.  
  118. #else /* L3MONITOR */
  119.  
  120. checkheard()
  121. {
  122.     register MHEARD *mhp;
  123.     register int i;
  124.  
  125.     i = 0;
  126.     mhp = heardl.prevhb;            /*start with one end of list*/
  127.     while( mhp != &heardl )            /* step thru all entries    */
  128.         if( cmpid( mhp->call, txfhdr ) )
  129.             break;            /* stop if match found      */
  130.         else                /* otherwise,               */
  131.         {
  132.             i++;            /* bump the counter         */
  133.             mhp = mhp->prevhb;    /* and step on to the next  */
  134.         }
  135.     if( mhp != &heardl )            /* if a match was found,    */
  136.     {
  137.         unlink( mhp );            /* then unlink it's buffer  */
  138.         mhp->packets++;            /* and increment pkt count  */
  139.     }
  140.     else                    /* otherwise ,              */
  141.     {
  142.         mhp = allocb();            /* allocate a new buffer    */
  143.         cpyid( mhp->call, txfhdr );    /* copy callsign into buffer*/
  144. #ifdef TEXNET
  145.         mhp->istexnet =
  146. #endif
  147.         mhp->isnode = mhp->istcpip = 0;    /* clear flags              */
  148.         mhp->packets = 1;        /* initialise packet count  */
  149.     }
  150.     mhp->port = rxfprt;            /* record which port heard  */
  151.     relink( mhp, heardl.prevhb );        /* put it at list head      */
  152.     mhp->lastheard = seconds;        /* mark heard time as 'now' */
  153. #ifdef METERS
  154.     mhp->dev = rxfdev;
  155.     mhp->sig_level = siglev;
  156. #endif
  157.     mhptr = mhp;                /* If too long, clear oldest*/
  158.     while( i-- >= mhlcount )        /* which is why we used 'i' */
  159.     {
  160.         mhp = heardl.lnext;        /* clear out from end of lst*/
  161.         dealoc( unlink( mhp ));        /* and return to free pool  */
  162.     }
  163. }
  164. #endif /* L3MONITOR */
  165. #endif
  166.  
  167. /*--------------------------------------------------------------------------
  168.  * This utility is part of the ACL subsystem. It checks if a buffer
  169.  * is part of the ACL, so that is preserved in warmstart.
  170.  * It is NOT used if INTEGRITY is defined as  integrity() is used instead.
  171.  */
  172.  
  173. #ifdef ACL
  174. #ifndef INTEGRITY
  175. BOOLEAN    isacl(buffer)        /* Test, ob buffer in ACLlisten ist         */
  176. ACLMB    *buffer;
  177. {
  178.   register ACLMB *nachb;
  179.  
  180.   for (nachb  = (ACLMB *) acl.prevaclb;    /* Nachbarnliste absuchen    */
  181.        nachb != (ACLMB *) &acl;
  182.        nachb  = (ACLMB *) nachb->prevaclb)
  183.   {
  184.       if (nachb == buffer) 
  185.           return(TRUE);
  186.   }
  187.   return(FALSE);        /* nicht gefunden                 */
  188. }
  189. #endif
  190. #endif
  191.  
  192. #ifdef INTEGRITY
  193.  
  194. /* The INTEGRITY routine is used to check whether a buffer is in use in
  195.  * a table, and to check that the tables ( linked lists ) are properly
  196.  * linked. ( it should also check the reverse links ! Doesn't yet. )
  197.  *
  198.  * The following table defines the tables that are included in the
  199.  * checking.
  200.  */
  201.  
  202. lhtyp *tables[] = {
  203.     &neigbl,
  204.     &destil,
  205. #ifdef ACL
  206.     &acl,
  207. #endif
  208. #ifdef IPROUTE
  209.     &IP_Routes,
  210.     &Arp_tab,
  211. #endif
  212.     NULL
  213. };
  214.  
  215. /* This is the checking routine. If the parameter is NULL, then the
  216.  * tables are checked to see they are linked correctly. If a value
  217.  * is passed then false or true are returned depending on whether
  218.  * the buffer is part of one of the tables.
  219.  */
  220.  
  221. integrity( buffer )
  222. lhtyp *buffer;
  223. {
  224.     register lhtyp **tableptr;
  225.     register unsigned i;
  226.     register lhtyp *table;
  227.     unsigned numbuffers;
  228.  
  229.     /* calculate the maximum possible buffers count
  230.      */
  231.     numbuffers = ( maxmem() - minmem() ) / sizeof( MBHEAD );
  232.  
  233.     /* step thru all tables
  234.     */
  235.     tableptr = &tables[0];
  236.     while( *tableptr != NULL )
  237.     {
  238.         for( table =  (*tableptr)->lnext, i = numbuffers ;
  239.              table != &((*tableptr)->lnext);
  240.              table =  table->lnext )
  241.         {
  242. #ifdef PK96
  243.             kick_wdog();
  244. #endif
  245.             if( buffer != NULL )        /* if param not NULL */
  246.             {
  247.                 if( buffer == table )    /* then return TRUE */
  248.                     return( TRUE );    /* if it is in table */
  249.             }
  250.             else                /* otherwise */
  251.             {
  252.                 if( --i == 0         /* count table size */
  253.                     || table->lnext->lprev != table
  254.                   )
  255.                 {            /* and init if too */
  256.                     inithd(*tableptr); /* large !! */
  257.                     break;
  258.                 }
  259.             }
  260.         }
  261.         tableptr++;
  262.     }
  263.     return( FALSE );
  264. }
  265.  
  266. #endif /* INTEGRITY */
  267.